package cn.edu.hpu.service;

import java.util.List;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.edu.hpu.dao.GroupDao;
import cn.edu.hpu.pojo.Group;
import cn.edu.hpu.pojo.Worker;
import cn.edu.hpu.util.TimeUtil;

@Service
@Transactional
public class GroupService {
	private GroupDao groupDao;

	public List<Group> findAll(){
		return groupDao.findAll();
	}
	public Group findA(String gid){
		return groupDao.get(gid);
	}
	public void save(Group group){
		Group g = new Group();
		Set<Worker> wSet = group.getWset();
		int rate = 0;
		for (Worker worker : wSet) {
			rate += worker.getWcount();
		}
		g.setGname(group.getGname());
		g.setGrate(rate);
		g.setCreatetime(TimeUtil.getTime());
		groupDao.save(g);
	}
	public void delete(String id){
		groupDao.del(id);
	}
	public void update(Group group){
		Group g = new Group();
		g.setGid(group.getGid());
		g.setGname(group.getGname());
		g.setGrate(group.getGrate());
		g.setCreatetime(group.getCreatetime());
		groupDao.update(g);
	}
	
	
	
	
	
	
	//setter,getter
	public GroupDao getGroupDao() {
		return groupDao;
	}
	@Autowired
	public void setGroupDao(GroupDao groupDao) {
		this.groupDao = groupDao;
	}
	
}
